package com.marisfrolg.service;

import com.marisfrolg.model.MyUserDetails;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

/**
 * @BelongsProject: oauth-demos
 * @BelongsPackage: com.marisfrolg.service
 * @Author: 毕苗苗
 * @CreateTime: 2023-01-04  13:19
 * @Description: TODO
 * @Version: 1.0
 */
@Service
public class MyUserDetailService implements UserDetailsService {

    @Autowired
    PasswordEncoder passwordEncoder;

    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
        if ("user".equals(s)) {
            MyUserDetails user = new MyUserDetails(s, passwordEncoder.encode(s));
            //根据角色查询权限 to-do
            user.setPerms("order-getOrder");
            user.setUserId(100100001L);
            return user;
        }
        if ("admin".equals(s)) {
            MyUserDetails user = new MyUserDetails(s, passwordEncoder.encode(s));
            //根据角色查询权限 to-do
            user.setPerms("order-createOrder");
            user.setUserId(100100002L);
            return user;
        }
        return null;
    }
//
//    UserDetails loadUserByOpenId(String s);
//
//    UserDetails loadUserByMessageCode(String phone,String messaeCode);

}